﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Quanlytruongtruongtieuhoc
{
    public partial class frmCapnhatxeplop : Form
    {
        string mahs, makhoi, nam;
        public frmCapnhatxeplop()
        {
            InitializeComponent();
        }

        private void frmCapnhatxeplop_Load(object sender, EventArgs e)
        {
            try
            {
                mahs = frmXemdanhsachlop.mahs;
                makhoi = frmXemdanhsachlop.makhoi.Substring(0, 1);
                nam = frmPhanconggvchunhiem.layNam();
                SqlDataAdapter ap = new SqlDataAdapter("select distinct ma_khoi+'.'+ma_lop as malop from lop_hoc_sinh where ma_khoi='" + makhoi + "'", clsKetnoi.con);
                DataTable lop = new DataTable();
                lop.Clear();
                ap.Fill(lop);
                cbMalop.DataSource = lop;
                cbMalop.DisplayMember = "malop";
            }
            catch (Exception ex) 
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btOk_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult kq = new DialogResult();
                kq = MessageBox.Show("Có chắc thay đổi không ?", "Thông tin", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (kq == DialogResult.OK)
                {
                    SqlCommand com = new SqlCommand("update lop_hoc_sinh set ma_khoi='" + cbMalop.Text.Substring(0, 1) + "', ma_lop='" + cbMalop.Text.Substring(2, 1) + "' where ma_hs='" + mahs + "' and nam_hoc='" + nam + "'", clsKetnoi.con);
                    com.ExecuteNonQuery();
                    MessageBox.Show("Cập nhật thành công.", "Thông tin", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    this.Hide();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
